Add a NUM_JOBS env var to builds
authorAlex Crichton <alex@alexcrichton.com>
Tue, 9 Sep 2014 22:01:31 +0000 (15:01 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 9 Sep 2014 22:05:32 +0000 (15:05 -0700)
Closes #539

src/cargo/ops/cargo_rustc/context.rs
src/doc/source/native-build.md
tests/test_cargo_compile.rs

index 35714b16384cf406813dea29125bc638393979b5..bb5e88301feb7694fe451f9f4065de378c0e80f4 100644 (file)
@@ -151,6 +151,8 @@ impl<'a, 'b> Context<'a, 'b> {
             self.build_requirements(pkg, target, Target, &mut HashSet::new());
         }
 
+        self.compilation.extra_env.insert("NUM_JOBS".to_string(),
+                                          Some(self.config.jobs().to_string()));
         self.compilation.root_output = self.layout(KindTarget).proxy().dest().clone();
         self.compilation.deps_output = self.layout(KindTarget).proxy().deps().clone();
 
index 03bda2b0142127c42c9cba9c24921e29a66c1cb5..bc253fa89a21210a882beb3686c4950cf7d86f68 100644 (file)
@@ -71,6 +71,8 @@ commands.
 * `OUT_DIR` - the folder in which all output should be placed.
 * `TARGET` - the target triple that is being compiled for. Native code should be
              compiled for this triple.
+* `NUM_JOBS` - the parallelism specified as the top-level parallelism. This can
+               be useful to pass a `-j` parameter to a system like `make`.
 * `DEP_<name>_OUT_DIR` - This variable is present for all immediate dependencies
                          of the package being built. The `<name>` will be the
                          package's name, in uppercase, with `-` characters
index 1caf58335eac68e3614c5ea2fdf4b286d8006c92..976dab4494f6b73019d7bce31797af09079016c1 100644 (file)
@@ -791,6 +791,7 @@ test!(custom_build_env_vars {
         .file("src/foo.rs", format!(r#"
             use std::os;
             fn main() {{
+                let _ncpus = os::getenv("NUM_JOBS").unwrap();
                 let out = os::getenv("OUT_DIR").unwrap();
                 assert!(out.as_slice().starts_with(r"{0}"));
                 assert!(Path::new(out).is_dir());